package com.entor.service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.entor.dao.IncomeDaoI;
import com.entor.dao.MenberDaoI;
import com.entor.model.BaseClass;
import com.entor.util.HighChartUtil;

@Service
public class ReportService {
	@Autowired
	private MenberDaoI mdi;
	@Autowired IncomeDaoI ici;
	
	public String getPieData(){
		String title = "会员性别比例图例";
		List<Map<String, Object>> list = new ArrayList<Map<String,Object>>();
		List<BaseClass> datas = mdi.selectSexConut();
		for(int i=0;i<datas.size();i++){
			BaseClass bc = datas.get(i);
			Map<String,Object> m1 = new HashMap<String, Object>();
			m1.put("name", bc.getSex());
			m1.put("y", bc.getDou()*100);
			if(i==1){
				m1.put("sliced",true); 
				m1.put("selected", true);
			}
			list.add(m1);
		}
		
		return HighChartUtil.getPie(title,list);
	}
	
	public String getColumn(String type){
		String x[] = {};
		double bs[] = {};
		List<Map<String, Object>> list = new ArrayList<Map<String,Object>>();
		List<BaseClass> listt = ici.selectMonandCon();
		for (int i=0;i<listt.size();i++) {
			BaseClass bc = listt.get(i);
			String name=bc.getName().substring(5,7)+"月";
				x=Arrays.copyOf(x, x.length+1);
				x[x.length-1]=name;
				bs=Arrays.copyOf(bs, bs.length+1);
				bs[bs.length-1]=bc.getDou();
			
			
		}
		
		String title = "财务流量";
		String subtitle = "(不同时间段财务总流量柱形图)";
		String y = "流量总计 (元)";
		String danwei="元";
		
		
		
		
		Map<String, Object> m1 = new HashMap<String, Object>();
		m1.put("name", "月份");
		
		
		
		m1.put("data", bs);
		list.add(m1);
		
		return HighChartUtil.getColumn(title, subtitle, y, x, list,type,danwei);
	}

}
